/**
  ******************************************************************************
  * @file    Project/Api/ScanKey.c 
  * @author  zlf
  * @version V1.0.0
  * @date    2016-04-05
  * @brief   ScanKey.c module
  ******************************************************************************
  */

/* Includes ------------------------------------------------------------------*/
#include "ScanKey.h"

/* Private functions ---------------------------------------------------------*/

/**
  * @brief  TThis function is to scan the key action of button.
  * @param  None
  * @retval None
  */


KEY_TypeDef Key_Scan( void )
{
	//record the key value pressed last time
	static KEY_TypeDef Old_MSKey = KEY_NOKEY;
	//record the key value pressed currently
	KEY_TypeDef Cur_MSKey = KEY_NOKEY;
	
	if( BTN_OK_IN == BTN_PRESSED )
	{
		Cur_MSKey = KEY_OK;
	}
	else if( BTN_CANCEL_IN == BTN_PRESSED )
	{
		Cur_MSKey = KEY_CANCEL;
	}	
	else if( BTN_UP_IN == BTN_PRESSED )
	{
		Cur_MSKey = KEY_UP;
	}
	else if( BTN_DOWN_IN == BTN_PRESSED )
	{
		Cur_MSKey = KEY_DOWN;
	}
	else if( BTN_SHIFT_IN == BTN_PRESSED )
	{
		Cur_MSKey = KEY_SHIFT;
	}
	

	//No key is pressed
	if( Cur_MSKey == KEY_NOKEY )
	{
		Old_MSKey = KEY_NOKEY;
		return KEY_NOKEY;
	}

	//New key with anti-jamming
	if( Cur_MSKey == Old_MSKey )
	{
		return Cur_MSKey;
	}

	//New key without anti-jamming
	Old_MSKey = Cur_MSKey;

	
	return KEY_NOKEY;
}



